/**
Custom module for you to write your own javascript functions
**/
var Custom = function () {

    // private functions & variables

    var myFunc = function (text) {
        alert(text);
    }

    // public functions
    return {

        //main function
        init: function () {
            //initialize here something.            
        },

        //some helper function
        doSomeStuff: function () {
            myFunc();
        }

    };

} ();

$.fn.loadPageAjax = function (options) {
    var defaults = { "url": '/UserCP/MainManagement/_Manager', "wapper": "#mainTabContent" };
    var settings = $.extend(defaults, options || {});
    $(this).bind("click", function (e) {
        e.preventDefault() ? e.preventDefault() : e.returnValue;
        $(this).parent().addClass("active");
        $(this).parent().siblings().removeClass("active");
        var thisClick = $(this);
        $(settings.wapper).html("<div class='reload-page'><div class='reload-icon'></div></div>");
        setTimeout(function () {
            $.ajax({
                type: "GET",
                cache: false,
                url: settings.url,
                dataType: "html",
                success: function (res) {
                    $(settings.wapper).children().remove();
                    $(settings.wapper).append(res);

                    if (thisClick.attr("id") === "tabOverviewMan") {
                        $("#tabMessageMan").loadPageAjax({ "url": "/UserCP/MessageManagement/_Manager" });
                        $("#tabPersionalSetting").loadPageAjax({ "url": "/UserCP/UserManagement/_ProfileSettings" });
                    }
                    else if (thisClick.attr("id") === "tabMessageMan") {
                        Inbox.init();
                    }
                    App.fixContentHeight();
                    App.initUniform();
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    toggleButton(el);
                },
                async: false
            });
        }, 300);
    });
}
/***
Usage
***/
$("#tabOverviewMan").loadPageAjax();
$("#tabOrderMan").loadPageAjax({ "url": "/UserCP/OrderManagement/_Manager" });
$("#tabWorkMan").loadPageAjax({ "url": "/UserCP/WorkManagement/_Manager" });
$("#tabAccountMan").loadPageAjax({ "url": "/UserCP/AccountManagement/_Manager" });
$("#tabPersionalSetting").loadPageAjax({ "url": "/UserCP/UserManagement/_ProfileSettings"});
$("#tabMessageMan").loadPageAjax({ "url": "/UserCP/MessageManagement/_Manager" });
